package org.kernely.security.ui.group.mgmt;

import org.kernely.ui.mvp.IKernelyView;

import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Table;

public class GroupManagementView extends GridLayout implements IKernelyView {

	/**
	 * The Serial Version ID
	 */
	private static final long serialVersionUID = 6312090241501372232L;
	
	/**
	 * The button Layout
	 */
	private HorizontalLayout hlayout;
	
	/**
	 * Add group button
	 */
	private Button bAddGroup;
	
	/**
	 * The edit group button
	 */
	private Button bEditGroup;
	
	/**
	 * The delete group button
	 */
	private Button bDeleteGroup;
	
	/**
	 * The group table
	 */
	private Table table;

	/**
	 * @see org.kernely.ui.mvp.IKernelyView#getComponent()
	 */
	public Component getComponent() {
		return this;
	}

	/**
	 * GroupManagementView's constructor
	 */
	public GroupManagementView(){
		// Configuration of the GridLayout
		this.setRows(2);
		this.setColumns(1);
		
		this.hlayout = new HorizontalLayout();
		this.bAddGroup = new Button("Add a group");
		this.bEditGroup = new Button("Edit a group");
		this.bEditGroup.setEnabled(false);
		this.bDeleteGroup = new Button("Delete a group");
		this.bDeleteGroup.setEnabled(false);
		bEditGroup.setImmediate(true);
		bDeleteGroup.setImmediate(true);
		this.table = new Table();
		
		this.table.setSizeFull();
		this.table.setPageLength(20);
		this.table.setHeight(100, Sizeable.UNITS_PERCENTAGE);
		this.table.addContainerProperty("Name", String.class, null);
		this.table.addContainerProperty("Users", Integer.class, null);
		this.table.setSelectable(true);
		this.table.setImmediate(true);
		
		this.table.setSortContainerPropertyId("Name");
		this.table.setSortAscending(true);
		
		this.hlayout.addComponent(this.bAddGroup);
		this.hlayout.addComponent(this.bEditGroup);
		this.hlayout.addComponent(this.bDeleteGroup);
		this.hlayout.setMargin(true, true, true, true);
		this.hlayout.setSpacing(true);
		
		this.addComponent(this.hlayout,0, 0);
		this.addComponent(this.table, 0, 1);
		
		this.setSizeFull();
	}

	/**
	 * Gets the add group button
	 * @return the button add group
	 */
	public final Button getbAddGroup() {
		return bAddGroup;
	}
	
	/**
	 * Gets the edit group button
	 * @return the button edit group
	 */
	public final Button getbEditGroup() {
		return bEditGroup;
	}
	
	/**
	 * Gets the delete group button
	 * @return the button delete group
	 */
	public final Button getbDeleteGroup() {
		return bDeleteGroup;
	}

	/**
	 * Gets the group table
	 * @return the group table
	 */
	public final Table getTable() {
		return table;
	}

}
